package com.louis.mail;

import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.InputStreamSource;
import org.springframework.util.StringUtils;

import java.io.File;

/**
 * 
 * <p>
 * FileAttachment
 * </p>
 * 
 * @author louis
 * @DateTime Jul 29, 2011 3:24:07 PM
 * @version 1.0.0
 */
public class FileAttachment implements Attachment {
	private String attachmentName;
	private File file;

	public FileAttachment(File file, String attachmentName) {
		this.attachmentName = attachmentName;
		this.file = file;
	}

	public String getAttachmentName() {
		if (StringUtils.hasText(attachmentName)) {
			return this.attachmentName;
		}
		return file.getName();
	}

	public InputStreamSource getInputStreamSource() {
		return new FileSystemResource(file);
	}
}